import UploadList from '@/components/UploadList'
import { equipmentGrant, equipmentRecovery, equipmentExit } from '@/api/quality/projectMeterageEquipmentAccount'
import { checkType, equipmentBelongToArr, checkStatusArr} from '@/views/quality/equipmentManagement/constant/dictionary.js'


const publicFormData = [
    {
        type: 'a-input',
        keyName: 'mdName',
        label: '设备名称',
        span: 12,
        disabled: true,
    },
    {
        type: 'a-input',
        keyName: 'mdCode',
        label: '设备编号',
        span: 12,
        disabled: true,
    },
    {
        type: 'a-input',
        keyName: 'specificationModel',
        label: '规格型号',
        span: 12,
        disabled: true,
    },
    {
        type: 'a-select',
        keyName: 'mdBelongTo',
        label: '设备归属',
        span: 12,
        data: equipmentBelongToArr,
        disabled: true,
    },
]
const releaseAndRecoveryPublicData = (tag)=>{
   return [
     ...publicFormData,
     {
        type: 'a-input',
        keyName: 'receiverCompany',
        label: '领用单位',
        span: 12,
        disabled: tag!=='grant',

     },
     {
        type: 'a-input',
        keyName: 'receiver',
        label: '领用人',
        span: 12,
        disabled: tag!=='grant',
     },
     {
        type: 'a-date-picker',
        keyName: 'receiveTime',
        label: '领用时间',
        span: 12,
        disabled: tag!=='grant',
        attrs: {
            valueFormat: 'YYYY-MM-DD 00:00:00',
            format: 'YYYY-MM-DD'
        }
     },
     {
        type: 'a-input',
        keyName: 'remarks',
        label: '领用备注',
        span: 12,
        disabled: tag!=='grant',
     },
     {
        type: 'a-input',
        keyName: 'creatorName',
        label: '创建人',
        span: 12,
        disabled: true,
     },
     {
        type: 'a-date-picker',
        keyName: 'createTime',
        label: '创建时间',
        span: 12,
        disabled: true,
        attrs: {
            valueFormat: 'YYYY-MM-DD 00:00:00',
            format: 'YYYY-MM-DD'
        }
     },
   ]
}
// 设备发放Modal
const grantModalData = {
    title: '计量设备发放',
    confirmBtnText: '确定发放',
    api: equipmentGrant,
    formList: releaseAndRecoveryPublicData('grant'),
    rules: {
        receiverCompany: [{ required: true, message: '请输入领用单位', trigger: 'blur' }],
        receiver: [{ required: true, message: '请输入领用人', trigger: 'blur' }],
        receiveTime: [{ required: true, message: '请选择领用时间', trigger: 'change' }],
    }
}

// 设备收回Modal
const recoveryModalData = {
    title: '计量设备收回',
    confirmBtnText: '确定收回',
    api: equipmentRecovery,
    formList: [
        ...releaseAndRecoveryPublicData('recovery'),
        {
            type: 'a-date-picker',
            keyName: 'takeBackTime',
            label: '收回时间',
            span: 12,
            attrs: {
                valueFormat: 'YYYY-MM-DD 00:00:00',
                format: 'YYYY-MM-DD'
            }
        },
        {
            type: 'a-input',
            keyName: 'takeBackRemark',
            label: '收回备注',
            span: 12,
        },
    ],
    rules: {
        takeBackTime: [{ required: true, message: '请选择收回时间', trigger: 'change' }],
    }
}

// 设备退场Modal
const exitModalData = {
    title: '计量设备退场',
    confirmBtnText: '确定退场',
    api: equipmentExit,
    formList: [
        ...publicFormData,
        {
            type: 'a-date-picker',
            keyName: 'outProjectTime',
            label: '退场时间',
            span: 12,
            attrs: {
                valueFormat: 'YYYY-MM-DD 00:00:00',
                format: 'YYYY-MM-DD'
            }
        },
        {
            type: 'a-input',
            keyName: 'outProjectRemark',
            label: '退场原因',
            span: 12,
        },
    ],
    rules: {
        outProjectTime: [{ required: true, message: '请选择退场时间', trigger: 'change' }],
    }   
}

// 设备检定记录Modal
const verificationModal = {
    title: '计量设备检定记录',
    confirmBtnText: '确定检定',
    formList: [
        {
            type: 'a-input',
            keyName: 'mdName',
            label: '设备名称',
            span: 12,
            disabled: true,
        },
        {
            type: 'a-input',
            keyName: 'mdCode',
            label: '设备编号',
            span: 12,
            disabled: true,
        },
        {
            type: 'a-date-picker',
            keyName: 'beforeAppraisalDate',
            label: '上次检定日期',
            span: 12,
            disabled: true,
            attrs: {
                valueFormat: 'YYYY-MM-DD 00:00:00',
                format: 'YYYY-MM-DD'
            }
        },
        {
            type: 'a-input',
            keyName: 'appraisalCycle',
            label: '检定周期（月）',
            span: 12,
            disabled: true,
        },
        {
            type: 'a-select',
            keyName: 'appraisalType',
            label: '检定方式',
            data: checkType,
            span: 12,
        },
        {
            type: 'a-date-picker',
            keyName: 'currentAppraisalDate',
            label: '本次检定日期',
            span: 12,
            attrs: {
                valueFormat: 'YYYY-MM-DD 00:00:00',
                format: 'YYYY-MM-DD'
            }
        },
        {
            type: 'a-input',
            keyName: 'appraisalCompany',
            label: '检测单位',
            span: 12,
        },
        {
            type: 'a-select',
            keyName: 'appraisalStatus',
            label: '检定结果',
            data: checkStatusArr,
            span: 12,
        },
        {
            type: 'a-textarea',
            keyName: 'appraisalDetail',
            label: '检定详情',
            span: 24,
        },
        {
            type: 'a-input',
            keyName: 'fillInUserName',
            label: '填写人',
            span: 12,
            disabled: true,
        },
        {
            type: 'a-date-picker',
            keyName: 'fillInTime',
            label: '填写时间',
            span: 12,
            disabled: true,
            attrs: {
                valueFormat: 'YYYY-MM-DD 00:00:00',
                format: 'YYYY-MM-DD'
            }
        },
        {
            keyName: 'fileIds',
            type: UploadList,
            span: 24,
            label: '附近上传',
            attrs: {
                businessCode: 'PM44'
            },
        },
    ],
    rules: {
        appraisalType: [{ required: true, message: '请选择检定方式', trigger: 'change' }],
        currentAppraisalDate: [{ required: true, message: '请选择本次检定日期', trigger: 'change' }],
        appraisalCompany: [{ required: true, message: '请输入检测单位', trigger: 'blur' }],
        appraisalStatus: [{ required: true, message: '请选择检定结果', trigger: 'change' }],
    } 
}

export {
    grantModalData,
    recoveryModalData,
    exitModalData,
    verificationModal
}